
import { ProfessionalAction, ProfessionalActionTypes } from '../actions';
import { TreeItem } from '../../components';

export interface ProfessionalState {
    data: TreeItem[];
    loading: boolean;
    loaded: boolean;
}

export const initialProfessionalState = {
    data: [],
    loaded: false,
    loading: false
};

export function professionalReducer(
    state: ProfessionalState = initialProfessionalState, 
    action: ProfessionalAction
): ProfessionalState {
    switch(action.type) {
        case ProfessionalActionTypes.LOAD_PROFESSIONAL: {
            return {
                ...state,
                loaded: false,
                loading: true
            }
        }
        case ProfessionalActionTypes.LOAD_PROFESSIONAL_FAIL: {
            return {
                ...state,
                loaded: false,
                loading: false
            }
        }
        case ProfessionalActionTypes.LOAD_PROFESSIONAL_SUCCESS: {
            return {
                ...state,
                data: action.payload,
                loaded: true,
                loading: false
            }
        }
        default: {
            return state;
        }
    }
}
